import postcssPresetEnv from "postcss-preset-env";
import pxToViewport from "postcss-px-to-viewport-8-plugin";
import autoprefixer from "autoprefixer";

// 兼容 Windows 与 POSIX 路径分隔符
const mobileInclude = [/[/\\]src[/\\]views[/\\]mobile[/\\]/, /[/\\]src[/\\]components[/\\]mobile[/\\]/];
const pcInclude = [/[/\\]src[/\\]views[/\\]pc[/\\]/, /[/\\]src[/\\]components[/\\]pc[/\\]/];

export default {
    plugins: [
        postcssPresetEnv({
            stage: 3,
            features: {
                "nesting-rules": true,
                "custom-media-queries": true,
            },
        }),
        // 仅转换 mobile/ 目录，按 750 设计稿
        pxToViewport({
            viewportWidth: 750,
            viewportHeight: 1334,
            unitPrecision: 5,
            viewportUnit: "vw",
            selectorBlackList: [".ignore", ".hairlines"],
            minPixelValue: 1,
            mediaQuery: false,
            include: (filePath) => {
                if (!filePath) return false;
                return mobileInclude.some((re) => re.test(filePath));
            },
            exclude: [/node_modules/],
        }),
        // 仅转换 pc/ 目录，按 1440 设计稿
        pxToViewport({
            viewportWidth: 1440,
            unitPrecision: 5,
            viewportUnit: "vw",
            selectorBlackList: [".ignore", ".hairlines"],
            minPixelValue: 1,
            mediaQuery: false,
            include: (filePath) => {
                if (!filePath) return false;
                return pcInclude.some((re) => re.test(filePath));
            },
            exclude: [/node_modules/],
        }),
        autoprefixer({
            overrideBrowserslist: ["Android >= 4.4", "iOS >= 10", "Chrome >= 60", "Safari >= 10"],
        }),
    ],
};
